//
//  NSString+SpecificString.m
//  LKMassMessage
//
//  Created by LIUKUN-PC on 16/1/26.
//  Copyright © 2016年 liukun. All rights reserved.
//

#import "NSString+SpecificString.h"
#import <CoreFoundation/CoreFoundation.h>
#import "NSDate+Utilities.h"

@implementation NSString (SpecificString)

- (NSString *)phonetic {
    NSMutableString *mutableString = [self mutableCopy];
    CFStringTransform((__bridge CFMutableStringRef)mutableString, NULL, kCFStringTransformMandarinLatin, NO);
    NSLog(@"%@",mutableString);
    CFStringTransform((__bridge CFMutableStringRef)mutableString, NULL, kCFStringTransformStripDiacritics, NO);
    NSLog(@"%@",mutableString);
    return [mutableString copy];
}

- (NSString *)phoneticNoSpace {
    return  [[self phonetic] stringByReplacingOccurrencesOfString:@" " withString:@""];
}

+ (NSString *)stringWithDecimalDoubleValue:(double)value {
    if ((int)(value * 10) % 10 == 0) {
        return [NSString stringWithFormat:@"%.0f", value];
    }
    return [NSString stringWithFormat:@"%.1f", value];
}

- (NSDate *)dateWithFormat:(NSString *)format {
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = format;
    return [formatter dateFromString:self];
}

- (NSString *)stringByremoveRepeatedSuffix {
    NSMutableArray<NSString *> *mArray = [[self componentsSeparatedByString:@"."] mutableCopy];

    
    NSMutableIndexSet *mIndexSet = [NSMutableIndexSet indexSet];
    for (NSInteger i = mArray.count - 1; i > 1; i--) {
        if ([mArray[i] isEqualToString:mArray[i - 1]]) {
            [mIndexSet addIndex:i];
        }
    }
    __block NSString *string = self;
    [mIndexSet enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
        string = [string substringToIndex:string.length - mArray[idx].length - 1];
    }];
    return string;
    
    

}


+ (NSString *)stringWithIntegerValue:(NSInteger)value {
    NSString *numberStr = [NSString stringWithFormat:@"%ld", value];
    if (value >= 10000 && value < 100000000) {
        numberStr = [NSString stringWithFormat:@"%.1lf万", value / 10000.0];
    } else if (value >= 100000000) {
        numberStr = [NSString stringWithFormat:@"%.1lf亿", value / 100000000.0];
    }
    return numberStr;

}

+ (NSString *)stringWithDateFormat:(NSString *)dateFormat timeInterval:(NSTimeInterval)timeInterval {
    return [[NSDate dateWithTimeIntervalSince1970:timeInterval] stringWithFormat:dateFormat];
}



@end
